package org.dtrd.modules.patient.entity.bean;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveOverview;
import org.dtrd.modules.patient.entity.po.DtrdEntRdPatient;

import java.util.Date;
import java.util.Random;

/**
 * @author xiao
 */
@Data
@ApiModel(value = "患者信息")
public class PatientPublicAccountInfo {

    @ApiModelProperty(value = "患者id", required = true)
    private Integer patientId;

    @ApiModelProperty(value = "手机号码", required = true)
    private String patientsMobile;

    @ApiModelProperty("患者姓名")
    private String patientsName;

    @ApiModelProperty("出生日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date patientsBirthday;

    @ApiModelProperty("年龄")
    private Integer age;

    @ApiModelProperty(value = "患者性别", notes = "1-男,2-女")
    private Integer patientsSex;
    @ApiModelProperty(value = "患者性别文本")
    private String patientsSexText;

    @ApiModelProperty("患者头像")
    private String patientsImg;

    @ApiModelProperty("糖尿病诊断结果，1-未确诊， 2-已确诊")
    private Integer patientsDiabetisDiagnose;
    @ApiModelProperty("诊断结果文本")
    private String patientsDiabetisDiagnoseText;

    @ApiModelProperty("糖尿病类型")
    private Integer patientsDiabetisType;
    @ApiModelProperty("糖尿病类型名称")
    private String patientsDiabetisTypeName;

    @ApiModelProperty("确诊日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date patientsConfirmedDate;

    @ApiModelProperty("病情描述")
    private String patientsSymptoms;

    @ApiModelProperty("所在城市id")
    private Integer cityId;

    @ApiModelProperty("所在省份id")
    private Integer provinceId;

    @ApiModelProperty("所在城市")
    private String location;

    @ApiModelProperty("是否购买服务包, 1-是，0-否")
    private Integer buyPackage = new Random().nextInt(2);

    @ApiModelProperty("糖化血红蛋白")
    private Float hba1c;

    @ApiModelProperty("血糖空腹")
    private Float sugarLimosis;

    @ApiModelProperty("早餐后血糖")
    private Float sugarAfterBreakfast;

    @ApiModelProperty("午餐前血糖")
    private Float sugarBeforeLunch;

    @ApiModelProperty("午餐后血糖")
    private Float sugarAfterLunch;

    @ApiModelProperty("晚餐前血糖")
    private Float sugarBeforeDinner;

    @ApiModelProperty("晚餐后血糖")
    private Float sugarAfterDinner;

    @ApiModelProperty("睡前血糖")
    private Float sugarBeforeSleep;

    @ApiModelProperty("凌晨血糖")
    private Float sugarEarlyDay;

    @ApiModelProperty("昵称")
    private String patientsNickname;

    @ApiModelProperty("身份证")
    private String patientsIdcard;

    @ApiModelProperty("身高")
    private Integer patientsHeight;

    @ApiModelProperty("体重")
    private Float patientsWeight;

    public PatientPublicAccountInfo parseFromPO(DtrdEntRdPatient po) {
        patientId = po.getDataId();
        patientsName = po.getPatientsName();
        cityId = po.getPatientsCityId();
        provinceId = po.getPatientsProvinceId();
        patientsMobile = po.getPatientsMobile();
        if (po.getPatientsBirthday() != null) {
            patientsBirthday = po.getPatientsBirthday();
            age = DateUtil.ageOfNow(po.getPatientsBirthday());
        }
        patientsImg = po.getPatientsImg();
        patientsSex = po.getPatientsSex();
        patientsSexText = Constant.Sex.valueOf(po.getPatientsSex()).getName();
        patientsSymptoms = po.getPatientsSymptoms();
        patientsNickname = po.getPatientsNickname();
        patientsIdcard = po.getPatientsIdCard();
        patientsHeight = po.getPatientsHeight();
        patientsWeight = po.getPatientsWeight();
        return this;
    }

    public PatientPublicAccountInfo parseFromPO(DtrdEntRdArchiveOverview overview) {
        Integer ifDiabetes = overview.getIfDiabetes();
        patientsDiabetisDiagnose = ifDiabetes;
        if (ifDiabetes != null) {
            patientsDiabetisDiagnoseText = Constant.DiagnoseStatus.valueOf(ifDiabetes).getName();
            // 已确诊才显示糖尿病类型
            if (ifDiabetes.equals(Constant.DiagnoseStatus.HAD_DIAGNOSED.getType())) {
                Integer diabetesType = overview.getDiabetesType();
                patientsDiabetisType = diabetesType;
                if (diabetesType != null) {
                    patientsDiabetisTypeName = Constant.DiabetesType.valueOf(diabetesType).getName();
                }
                patientsConfirmedDate = overview.getDiabetesDiagnoseDate();
            }
        }
        hba1c = overview.getHba1c();
        sugarLimosis = overview.getSugarFasting();
        sugarAfterBreakfast = overview.getSugarBreakfastAfter();
        sugarBeforeLunch = overview.getSugarLunchBefore();
        sugarAfterLunch = overview.getSugarLunchAfter();
        sugarBeforeDinner = overview.getSugarSupperBefore();
        sugarAfterDinner = overview.getSugarSupperAfter();
        sugarBeforeSleep = overview.getSugarSleepBefore();
        sugarEarlyDay = overview.getSugarSleepAfter();
        return this;
    }

}